#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef struct list{
    int data;
    struct list *next;
}*ls;
ls create_list(ls head){
    int x;
    ls p;
    scanf("%d",&x);
    if(head==NULL){
        head=(ls)malloc(sizeof(struct list));
        p=head;
        head->data=x;
        head->next=NULL;
    }
    
    while(x!=-1){ 
        ls node=(ls)malloc(sizeof(struct list));
        node->data=x;
        node->next=NULL;
        //头插法
        // node->next=head->next;
        // head->next=node;
        //尾插法
        p->next=node;
        p=p->next;
        scanf("%d",&x);
    }
    return head;
}

ls reverse(ls head){
    if(head == NULL || head->next == NULL || head->next->next==NULL)  //判定返回
    ls beg = head->next;
	ls end = head->next->next;
	while (end != NULL) {
		//将 end 从链表中摘除
		beg->next = end->next;
		//将 end 移动至链表头
		end->next = head->next;
		head->next = end;
		//调整 end 的指向，另其指向 beg 后的一个节点，为反转下一个节点做准备
		end = beg->next;
	}
	return head;
}
void reverse_head(ls head){//头插法
   ls p,q;
   p=head->next;
   head->next=NULL;
   while(p){
        q=p;
        p=p->next;
        //断开q并按头插法插入新的head链表中
        q->next=head->next;
        head->next=q;
   }
}
void print_list(ls head){
    ls p=head->next;
    while(p){
        printf("%d->",p->data);
        p=p->next;
    }
    printf("\n");
}
int main(){
    ls head=NULL;
    head=create_list(head);
    print_list(head);
    ls rhead=reverse(head);
    print_list(rhead);
    return 0;
}